// index.js
// 获取应用实例
const app = getApp()
const formatTime = require('../../utils/util.js');

Page({
  data: {
    bannerList: [], // 轮播图
    recommendList: [], // 推荐歌单
    tabList: [{
      name: "每日推荐",
      picUrl: "/image/icon/recommend.png"
    }, {
      name: "私人FM",
      picUrl: "/image/icon/FM.png"
    }, {
      name: "歌单",
      picUrl: "/image/icon/songList.png"
    }, {
      name: "排行榜",
      picUrl: "/image/icon/topList.png"
    }, {
      name: "有声书",
      picUrl: "/image/icon/book.png"
    }, ], // tab菜单
  },
  // 点击搜索
  onSearch() {
    console.log("点击搜索");
  },
  // 点击推荐歌单
  onClickRecommendItem(e) {
    let item = e.currentTarget.dataset.item
    console.log(item, '点击推荐歌单');
    wx.navigateTo({
      url: '/pages/songList/songList?id=' + item.id,
    })
  },


  // 获取轮播图
  getBannerList() {
    app.http.request("/banner", {
      type: 1 // 0:pc 1:android  2:iphone 3:ipad
    }, "POST").then(res => {
      // console.log(res, 'banner');
      // console.table(res.banners, 'banner');
      if (res.code == 200) {
        this.setData({
          bannerList: res.banners
        })
      }
    })
  },
  // 获取推荐歌单
  getRecommendList() {
    app.http.request("/personalized", {
      limit: 10
    }, "POST").then(res => {
      if (res.code == 200) {
        this.setData({
          recommendList: res.result
        })
      }
    })
  },
  // 运行
  onLoad() {
    console.log(formatTime.formatTime(new Date()));
  },
  onReady() {
    this.getBannerList()
    this.getRecommendList()
  },

})